<?php

#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
include_once ("include/class.time.php5");
$svo = new db("svoptik");
$tools = new tool();
$time = new TimeUtil();

include_once ("include/global_fix_extern.inc");

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik.tpl",
	"navi" => "navi.tpl",
	"ticker" => "ticker.tpl",
	"gb" => "guestbook.tpl"
));
#--------------------------------------------------
$t->set_var(array (
	"FORWARD" => ""
));

#--------------------------------------------------
# CREATE NAVIGATION RIGHT
#--------------------------------------------------
$links = "";
$url[0] = array (
	"URL" => "javascript:;",
	"ONCLICK" => "onClick=\"javascript:window.open('new_gb.php5','','width=400,height=563,locationbar=no,scrollbars=no,statusbar=no,resizable=no')\" ",
	"URL-TEXT" => "Neuer Eintrag"
);
for ($i = 0; $i < count($url); $i++) {
	$links .= "
	        <tr height=\"15\">
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
				<td valign=\"top\"><a href=\"" . $url[$i]['URL'] . "\" " . $url[$i]['ONCLICK'] . " class=\"sitenav\">" . $url[$i]['URL-TEXT'] . "</a></td>
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
	       ";
}
$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "GUESTBOOK"
#--------------------------------------------------
global $limit;
$content = "";
$step_width = 5;
if (!isset ($limit))
	$limit = 0;

$start_value = $limit * $step_width;
$end_value = $limit + $step_width;
$get_max = $svo->doSQL("select * from " . $table['Guestbook'] . " order by gb_date desc;");
$max = $svo->countRows($get_max);
$gb_query = $svo->doSQL("select * from " . $table['Guestbook'] . " order by gb_date desc limit " . $start_value . "," . $end_value . ";");
while ($tupel = mysql_fetch_array($gb_query)) {
	if (!empty ($tupel['gb_email']))
		$author = "<a href=\"mailto:" . $tupel['gb_email'] . "\" class=\"news\">" . $tupel['gb_name'] . "</a>";
	else
		$author = $tupel['gb_name'];
	$t->set_var(array (
		"HEADLINE" => $tools->html_replace($tupel['gb_headline']
	), "DATUM" => $time->out($tupel['gb_date'], 'd'), "TEXT" => $tools->html_replace($tupel['gb_text']), "AUTHOR" => $author, "ANMERKUNG" => $tools->html_replace($tupel['gb_anmerk'])));
	$content .= $t->parse("", "gb", true);
}
if ($limit > 0)
	$BACKWARD = "<a href=\"guestbook.php5?limit=" . ($limit -1) . "\" class=\"news\" target=\"_self\">zur&uuml;ck</a>";
else
	$BACKWARD = "&nbsp;";
if ($max > (($limit +1) * $step_width))
	$FORWARD = "<a href=\"guestbook.php5?limit=" . ($limit +1) . "\" class=\"news\" target=\"_self\">weiter</a>";
else
	$FORWARD = "&nbsp;";

$gb_nav = "
  <div align=\"center\">
    <table width=\"80%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
     	<tr>
		    <td width=\"33%\" align=\"center\" valign=\"top\" class=\"newsText\">" . $BACKWARD . "</td>
		    <td width=\"34%\" align=\"center\" valign=\"top\" class=\"newsText\"><a href=\"#top\" class=\"news\">top</a></td>
		    <td width=\"33%\" align=\"center\" valign=\"top\" class=\"newsText\">" . $FORWARD . "</td>
		</tr>
    </table>
  </div>
  ";
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => "G&Auml;STEBUCH",
	"ticker" => $ticker,
	"content" => $content . "<br>" . $gb_nav . "<br>",
	"navi" => $right_nav,
	"SYNCHRONIZE" => " "
));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
